package com.zqc.login.service;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

@Service(timeout = 300000)
public class EmailServiceImpl implements EmailService {
    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String emailFrom;

    @Override
    public Boolean sendEmail(String email, String code) {
        try {
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            // 发送方
            simpleMailMessage.setFrom(emailFrom);
            // 接收方
            simpleMailMessage.setTo(email);
            // 主题
            simpleMailMessage.setSubject("注册验证码");
            // 内容
            simpleMailMessage.setText("您的注册验证码：" + code);

            javaMailSender.send(simpleMailMessage);
        } catch (Exception e) {
            return false;
        }

        return true;
    }
}
